<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>博客登陆页</title>

    <link rel="stylesheet" href="css/common.css">
    <link rel="stylesheet" href="css/login.css">
</head>

<body>
<div class="nav">
    <img src="pic/star.jpg" alt="">
    <span class="blog-title">我的日记系统</span>
    <div class="space"></div>
    <a class="nav-span" href="blog_list.html">主页</a>
    <a class="nav-span" href="blog_edit.html">写日记</a>
</div>

<div class="container-login">
    <div class="login-dialog">
        <h3>登陆</h3>
        <div class="row">
            <span>用户名</span>
            <input type="text" name="username" id="username">
        </div>
        <div class="row">
            <span>密码</span>
            <input type="password" name="password" id="password">
        </div>
        <div class="row1">
            <span>验证码</span>
            <input type="text" name="inputCaptcha" id="inputCaptcha">
            <img id="verificationCodeImg" src="/admin/captcha" style="cursor: pointer;" title="看不清换一张"/>
<!--            <input type="button" value="提交" id="checkCaptcha">-->
        </div>
        <div class="row">
            <button id="submit" onclick="login()">提交</button>
        </div>

    </div>
</div>
<script src="js/jquery.min.js"></script>
<script>
<!--    #是id,.是-->
    $("#verificationCodeImg").click(function (){
        //dt=，目的就是重新获取请求，因为get和post的区别
        //1.查询字符串的位置(get请求多数在url上，不是绝对的) 2.get(会缓存，通常支持幂等（相同时间，相同参数获取时间一样的，所有又可能会进行缓存，所以加上一个时间戳）
        $(this).hide().attr('src','/admin/captcha?dt='+new Date().getTime()).fadeIn();
    });
    function login() {
       // location.assign("blog_list.html");
        $.ajax({
            type:"get",
            url:"/user/login",
            data:{
                userName:$("#username").val(),
                password:$("#password").val(),
                captcha: $("#inputCaptcha").val()
            },

            success:function (result){
                if(result.code==200&&result.data!=null){
                    //密码正确
                    //存储Token
                    localStorage.setItem("usertoken",result.data);
                    location.href="blog_list.html";
                }else{
                    alert(result.errorMsg);
                }
            }
        })
    }
</script>
</body>

</html>